package com.e3.basdoc.employee.client;

import java.util.List;

import com.e3.basdoc.employee.model.EmployeeModel;
import com.e3.basdoc.employee.model.EmployeeQC;
import com.e3.template.tgf.TGFQueryDialog;
import com.e3.web.core.client.GwtAsyncCallback;
import com.e3.web.core.model.SuperQC;
import com.e3.web.widget.client.MyField;
import com.extjs.gxt.ui.client.widget.form.Field;

public class EmployeeQueryDialog extends TGFQueryDialog<EmployeeModel> {
	
	private EmployeeRPCServiceAsync service = EmployeeRPCService.Util.getInstance();

	@Override
	protected List<Field<?>> getFormFields() {
		String[] fNames = {EmployeeModel.CODE,EmployeeModel.NAME};
		return EmployeeHelper.INSTANCE.getFormFields(fNames);
	}

	@Override
	protected SuperQC getQueryCondition() {
		MyField<?> field = getMyFormField(EmployeeModel.CODE);
		String code = (String)field.getFieldValue();
		field = getMyFormField(EmployeeModel.NAME);
		String name = (String)field.getFieldValue();
				
		final EmployeeQC qc = new EmployeeQC();
		qc.setCode(code);
		qc.setName(name);
		return qc;
	}

	@Override
	protected void executeQueryService(SuperQC qc,GwtAsyncCallback<List<EmployeeModel>> callback) {
		service.getEmployeeByCondition((EmployeeQC)qc, getQueryAsyncCallBack(qc));
	}
}
